<?php


namespace addon\hotel\model;

use think\facade\Cache;
use app\model\BaseModel;

/**
 * 房号管理
 * @author Administrator
 *
 */
class RoomNo extends BaseModel
{
    /**
     * 添加房间
     * @param array $data
     */
    public function addRoomNo($data)
    {
        $ap_id = model('hotel_room_no')->add($data);
        Cache::tag("hotel_room_no")->clear();
        return $this->success($ap_id);
    }

    /**
     * 修改房间
     * @param array $data
     */
    public function editRoomNo($data, $condition)
    {
        $res = model('hotel_room_no')->update($data, $condition);
        Cache::tag("hotel_room_no")->clear();
        return $this->success($res);
    }

    /**
     * 删除房间
     * @param array $condition
     */
    public function deleteRoomNo($condition)
    {
        $res = model('hotel_room_no')->delete($condition);
        Cache::tag("hotel_room_no")->clear();
        return $this->success($res);
    }

    /**
     * 获取房间基础信息
     * @param int $ap_id
     * @return multitype:string mixed
     */
    public function getRoomNoInfo($room_no_id)
    {
        $cache = Cache::get("room_no_getRoomNoInfo_" . $room_no_id);
        if (!empty($cache)) {
            return $this->success($cache);
        }
        $res = model('hotel_room_no')->getInfo([ [ 'room_no_id', '=', $room_no_id ] ], '*');
        Cache::tag("hotel_room_no")->set("room_no_getRoomNoInfo_" . $room_no_id, $res);
        return $this->success($res);
    }

    public function getNewRoomNoInfo($condition)
    {

        $res = model('hotel_room_no')->getInfo($condition, '*');

        return $this->success($res);
    }

    /**
     * 获取房间列表
     * @param array $condition
     * @param string $field
     * @param string $order
     * @param string $limit
     */
    public function getRoomNoList($condition = [], $field = '*', $order = 'room_no_id desc', $limit = null)
    {
        $data = json_encode([ $condition, $field, $order, $limit ]);
        $cache = Cache::get("room_no_getRoomNoList_" . $data);
        if (!empty($cache)) {
            return $this->success($cache);
        }
        $list = model('hotel_room_no')->getList($condition, $field, $order, '', '', '', $limit);
        Cache::tag("hotel_room_no")->set("room_no_getRoomNoList_" . $data, $list);

        return $this->success($list);
    }

    /**
     * 获取房间分页列表
     * @param array $condition
     * @param number $page
     * @param string $page_size
     * @param string $order
     * @param string $field
     */
    public function getRoomNoPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'sort desc', $field = '*',$alias='a', $join=[])
    {
        $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
        $cache = Cache::get("room_no_getRoomNoPageList_" . $data);
        if (!empty($cache)) {
            return $this->success($cache);
        }

        $list = model('hotel_room_no')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
        Cache::tag("hotel_room_no")->set("room_no_getRoomNoPageList_" . $data, $list);
        return $this->success($list);
    }

}